/* eslint-disable import/no-anonymous-default-export */
import {
    addOfflineMsg,
    changeChatRecordStatus,
    chatRecordList,
    createInfo,
    delMessage,
    filterData,
    msgList,
    offlineMsgList,
    updateFilterData,
    spreadUpdate,
    spreadList
} from "../services/systemInfoApi";

export default {
    state: {
        data: [],
        createData: [],
        chatRecordData: [],
        offlineMsgData: [],
        filterData: '',
        spreadData:[]

    },
    effects: {
        async msgList(params) {
            const response = await msgList(params)

            if (response.code === 200) {
                this.saveMsgList({
                    data: response.data
                })
            }
        },
        async offlineMsgList(params) {
            const response = await offlineMsgList(params)

            if (response.code === 200) {
                this.saveOfflineMsgList({
                    offlineMsgData: response.data
                })
            }
        },
        async spreadList() {
            const response = await spreadList()

            if (response.code === 200) {
                this.saveScale({
                    spreadData: response.data
                })
            }
        },

        async filterDataList() {
            const response = await filterData()

            if (response.code === 200) {
                this.saveFilter({
                    filterData: response.data
                })
            }
        },

        async updateFilter(params) {
            return await updateFilterData(params)

        },
        async spredadUpdate(params) {
            return await spreadUpdate(params)

        },
        async addOfflineMsg(params) {
            return await addOfflineMsg(params)

        },
        async createInfo(params) {
            const response = await createInfo(params)

            if (response.code === 200) {
                this.saveCreate({
                    createData: response.data
                })
            }
        },
        async delMessage(params) {
            const response = await delMessage(params)

            if (response.code === 200) {
                this.saveDelMessage({
                    delMessageData: response.data
                })
            }
        },
        async changeChatRecordStatus(params) {
            const response = await changeChatRecordStatus(params)
        },
//聊天记录
        async chatRecordList(params) {
            const response = await chatRecordList(params)

            if (response.code === 200) {
                this.saveRecordList({
                    chatRecordData: response.data
                })
            }
        },
    },
    reducers: {
        saveMsgList(state, paylode) {
            return {
                ...state,
                ...paylode
            }
        },
        saveFilter(state, paylode) {
            return {
                ...state,
                ...paylode
            }
        },
        saveScale(state, paylode) {
            return {
                ...state,
                ...paylode
            }
        },
        saveOfflineMsgList(state, paylode) {
            return {
                ...state,
                ...paylode
            }
        },
        saveRecordList(state, paylode) {
            return {
                ...state,
                ...paylode
            }
        },
        saveCreate(state, paylode) {
            return {
                ...state,
                ...paylode
            }
        },
        saveDelMessage(state, paylode) {
            return {
                ...state,
                ...paylode
            }
        },
    }
}